package com.china08.yxyapi.api.manage.stu.mystudy.tifenbao.vedio;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.questionbank.YxyQuesbankKnowlegeRelFoundationKnowlege;
import com.china08.yxyapi.entity.db.res.YxyResResource;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.huixue.comm.YxyQuesbankKnowlegeRelFoundationKnowlegeRepository;
import com.china08.yxyapi.service.res.huixue.impl.PlanKnowWeikeServiceImpl;

/**
 * 学习计划——看视频是否拥有视频
 */
@RestController
public class TifenbaoPlanWeikeIsNotSchController extends YxyApiBaseController {

    @Autowired
    private PlanKnowWeikeServiceImpl planKnowWeikeServiceImpl;

    @Autowired
    private YxyQuesbankKnowlegeRelFoundationKnowlegeRepository yxyQuesbankKnowlegeRelFoundationKnowlegeRepository;

    @RequestMapping(value = "/api_yw/manage/stu/mystudy/tifenbao/scoreimprove/isnot/weike", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response) {

        List<YxyQuesbankKnowlegeRelFoundationKnowlege> knowleges = yxyQuesbankKnowlegeRelFoundationKnowlegeRepository
                .findByKnowId(request.getParameter("kid"));

        List<String> knows = new ArrayList<String>();

        for (YxyQuesbankKnowlegeRelFoundationKnowlege oldKnow : knowleges) {
            knows.add(oldKnow.getFoundationKnowId());
        }

        List<YxyResResource> yrrLst = planKnowWeikeServiceImpl.getWeiKeForPlanKnow(knows);

        RespModel model = new RespModel();
        if (yrrLst.size() > 0) {
            model.flag = true;
        } else {
            model.flag = false;
        }

        return model;
    }

    /**
     * 响应参数
     * 
     */
    protected static class RespModel extends YxyApiRespModel {
        // 是否存在视频
        public boolean flag;
    }
}
